/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Logica;

import java.awt.Color;
import java.awt.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author odmaestrams
 */
    
public class TableRender extends DefaultTableCellRenderer {
   
    @Override
    public Component getTableCellRendererComponent(JTable table,
    Object value,
    boolean isSelected,
    boolean hasFocus,
    int row,
    int column) {
        
      super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);
      if (value instanceof String && column == 4) {
            try {
                row = table.convertRowIndexToModel(row);
                String s = table.getModel().getValueAt(row, column).toString();
                System.out.println(s);
                System.out.println(row);
                System.out.println(column);
                SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
                Date date = (Date) formatter.parse(s);
                Calendar cal = Calendar.getInstance();
                cal.setTime(date);
 
                if (cal.before(Calendar.getInstance())) {
                    setForeground(Color.RED);
                } else {
                    setForeground(null);
                }
                return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 
            } catch (ParseException e) {
                System.out.println("Exception :" + e);
                return null;
            }
        } else {
            setForeground(null);
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        }
   }
}
